<template>
  <div id="indexMap-map" style="width:100%;height:658px;"></div>
  <div id="indexMap-mapDiv" class="ol-popup">
    <!-- 显示控件 -->
    <div id="indexMap-setDivPosition"  class="init-setDivPosition" style="display:none;">
      <!-- 切换卫星和街道地图 -->
      <p @click="switchMap" class="init-setDivPosition-selected">
        <template v-if="switchMapBool==false">
          <img src="@/assets/map/image/weixing-b.png" title="切换卫星地图"><br/><span>卫星图</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/jiedao-b.png" title="切换街道地图"><br/><span>街道图</span>
        </template>
      </p>
      <!-- 返回主界面 -->
      <p @click="zoomDefaultPosition" :class="{ 'init-setDivPosition-selected': zoomDefaultPositionBool==true }">
        <img src="@/assets/map/image/newImage/home.png" title="返回主界面"><br/><span>主界面</span>
      </p>
      <!-- 显示工具箱 -->
      <p @click="showHideToolsBoxDiv" :class="{ 'init-setDivPosition-selected': showHideToolsBox==false }">
        <template v-if="showHideToolsBox">
          <img src="@/assets/map/image/tools.png" title="打开工具箱"><br/><span style="border:0;">工具箱</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/tools.png" title="关闭工具箱"><br/><span style="border:0;">工具箱</span>
        </template>
      </p>
    </div>
    <!-- 工具箱 -->
    <div id="indexMap-ToolsBoxDiv" class="init-ToolsBoxDiv">
      <p @click="measureToolBox" :class="{ 'init-setDivPosition-selected': showHideMeasureTool==false }">
        <template v-if="showHideMeasureTool">
          <img title="开启测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
        </template>
        <template v-else>
          <img title="关闭测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
        </template>
      </p>
      <p @click="positionToolBox" :class="{ 'init-setDivPosition-selected': showHidePositionTool==false }">
        <template v-if="showHidePositionTool">
          <img title="开启定位工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">定位</span>
        </template>
        <template v-else>
          <img title="关闭定位工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">定位</span>
        </template>
      </p>
    </div>
    <!-- 所有工具 -->
    <div id="indexMap-AllToolsDiv" class="init-AllToolsDiv">
      <!-- 测量工具 -->
      <div id="indexMap-MeasureToolsDiv" class="init-AllToolsDivFloat">
        <p @click="measureDistance" :class="{ 'init-setDivPosition-selected': measureDistanceBool==false }">
          <template v-if="measureDistanceBool">
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="measureArea" :class="{ 'init-setDivPosition-selected': measureAreaBool==false }">
          <template v-if="measureAreaBool">
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="stopMeasure" :class="{ 'init-setDivPosition-selected': stopMeasureBool==false }">
          <template v-if="stopMeasureBool">
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="clearMeasure" :class="{ 'init-setDivPosition-selected': clearMeasureBool==false }">
          <template v-if="clearMeasureBool">
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
        </p>
      </div>
      <!-- 定位工具 -->
      <div id="indexMap-MousePositionDiv">
        <span><img class="init-jingd" src="@/assets/map/image/jingd.png" title="鼠标左键在地图上点击位置的经度值"></span>
        <input id="indexMap-MousePositionLon" type="text" value="">
        <span><img class="init-weid" src="@/assets/map/image/weid.png" title="鼠标左键在地图上点击位置的纬度值"></span>
        <input id="indexMap-MousePositionLat" type="text" value="">
        <p @click="clearPosition" :class="{ 'init-setDivPosition-selected': clearPositionBool==false }">
          <template v-if="clearPositionBool">
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="addPosition" :class="{ 'init-setDivPosition-selected': addPositionBool==false }">
          <template v-if="addPositionBool">
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
        </p>
      </div>
    </div>
    <!-- 弹出窗口 -->
    <!--<div id="indexMap-popup" class="new-ol-popup">
      <a href="#" id="indexMap-popup-closer" class="new-ol-popup-closer"></a>
      <div id="indexMap-popup-content"></div>
    </div>-->
    <!--右键菜单-->
    <div id="indexMap-contextmenu" class="new-popover" style="display:none;">
      <div class="new-triangle"></div>
      <div class="new-contextmenu">
        <!--<p @click="getDownloadFile"><span>查看报告</span></p>-->
      </div>
    </div>
    <!--历史设定地震点统计个数-->
    <!--<div v-show="allFeatureCountBool" style="position:absolute;right:20px;top:20px;background: #fff;padding:10px;border:1px solid gray;border-radius:5px;">
      历史设定地震点统计总数：{{allFeatureCount}}
    </div>-->
  </div>
</template>
<script>
  import '@/assets/map/ol/ol.css';
  import { getProjection,getResolutions,getTiandituVecMap,getTiandituVecText,getTiandituImgMap,getTiandituImgText,
    getRESTLayer,getVectorTileLayer,iServerHttp,meterToDegree } from "@/map/projMap.js";
  import Map from 'ol/Map';
  import View from 'ol/View';
  import VectorLayer from 'ol/layer/Vector';
  import {Vector as VectorSource} from 'ol/source'
  import {Control} from 'ol/control';
  // import ScaleLine from 'ol/control/ScaleLine';
  import WKT from 'ol/format/WKT';
  import GeoJSON from 'ol/format/GeoJSON';
  import Overlay from 'ol/Overlay';
  import Feature from 'ol/Feature';
  import Point from 'ol/geom/Point';
  import Polygon from 'ol/geom/Polygon';
  import LineString from 'ol/geom/LineString';
  import Circle from 'ol/geom/Circle';
  import {fromCircle} from 'ol/geom/Polygon';
  import {Fill, Stroke, Style, Icon, Circle as CircleStyle,Text} from 'ol/style';
  import {Select, Draw, Modify, Snap, Translate} from 'ol/interaction';
  import {getArea, getLength} from 'ol/sphere';
  import {unByKey} from 'ol/Observable';
  import {boundingExtent} from 'ol/extent';
  import dingweiImg from '@/assets/map/image/newImage/blueMarker.png';
  import { MapService,GetFeaturesByGeometryParameters,FeatureService } from '@supermap/iclient-ol';
  import { ElLoading } from 'element-plus'

  export default {
    name: "IndexMap",
    components: {

    },
    props:{
      allRadioIndexData: {//全部序号列表
        type:Array,
        required:true,
        default:[]
      },
      allListData: {//全部查询结果列表
        type:Array,
        required:true,
        default:[]
      },
      typeCodeDataList: {//选择图层的版本号数据列表
        type:Array,
        required:true,
        default:[]
      },
      resetClearAllBool: {//是否重置清空全部图层数组
        type:Boolean,
        required:false,
        default:false
      },
      dataTypeInfoArray:{//图层数据类型数组
        type: Array,
        required:false,
        default: []
      },
      mapDrawType: {//是否开启地图圈选查询
        type:String,
        required:false,
        default: ""
      },
      allDrawGeomText: {//地图圈选空间数据
        type:String,
        required:false,
        default: ""
      },
      circleForm: {//地图圈选查询选择表类型
        type:Object,
        required:false,
        default: ""
      },
      tableData: {//地图圈选查询数据结果
        type:Array,
        required:false,
        default: ""
      },
    },
    emits:["getDetailDataById","getLegendHtml","getDownloadName","getAllDrawGeom"],
    data() {
      return {
        str: "indexMap",
        map: null,
        url: "https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China_4326",//中国地图
        center: [105, 34],
        zoom: 4,
        mapLoadingBool:false,//是否正在查询参数
        zoomDefaultPositionBool:true,//显示主界面
        switchMapBool:false,//切换地图
        layer1:null,//天地图街道图
        layer2:null,
        layer3:null,//天地图卫星图
        layer4:null,
        draw:null,//矢量绘制
        snap:null,
        select:null,
        modify:null,
        drag:null,
        source:null,//矢量绘制图层数据
        measureSource:null,//测量结果图层数据
        measure:null,//测量工具
        sketch:null,
        helpTooltipElement:null,
        helpTooltip:null,
        measureTooltipElement:null,
        measureTooltip:null,
        measureTooltipArray:[],//全部测量结果Overlay数组
        showHideMeasureTool:true,//显示|隐藏测量工具
        measureDistanceBool:true,
        measureAreaBool:true,
        stopMeasureBool:true,
        clearMeasureBool:true,
        showHidePositionTool:true,//显示|隐藏定位工具
        addPositionBool:true,
        clearPositionBool:true,
        popupInfoLayer:null,//弹出窗口
        showHideToolsBox:true,
        //addressMatchService:null,//地址匹配
        addressUrl:"https://iserver.supermap.io/iserver/services/addressmatch-Address/restjsr/v1/address",
        selectFeature:null,//选中要素
        allDataList:[],//全部查询结果数组
        typeCodeDataArray:[],//选择图层的版本号数据列表
        allRadioIndexList:[],//全部序号列表
        allBaseVectorLayerArray:[],//全部图层数组列表
        //超图图层服务使用数据
        selectLayerIndex:null,//选中图层的序号
        allRestVectorLayerArray:[],//全部超图图层数组
        showLayerNum:0,//当前显示的图层数量
        queryLayerNum:0,//已查询的图层数量
        resultDataTypeInfo:null,//已查询到图层要素结果的数据类型信息
        resultDataId:null,//已查询到的图层要素主键ID
        resultDataFeature:null,//已查询到的图层要素数据
        selectFeatureLayer:null,//选中要素高亮显示图层
        loading:null,//是否正在查询
        allDataTypeInfoArray:[],//全部超图图层信息数组
        allFeatureCountArray:[],//统计全部图层要素数量数组
        allFeatureCountBool:false,//是否显示统计面板
        allFeatureCount:0,//统计全部图层要素数量
        //历史设定地震点数据图层数据集
        tempDataSetList:[
          "历史设定地震点数据",
        ],
        contextmenuLayer:null,//右键弹出窗口
        queryMapDrawType:"",//是否开启地图圈选参数（StopDraw关闭地图圈选 Polygon多边形绘制 Rectangle矩形绘制 Clear清空）
        drawGeomText:"",//地图圈选空间数据
        queryFeatureLayer:null,//地图圈选要素高亮显示图层
        circleFormObj:null,//地图圈选查询选择表类型
        tableDataList:[],//地图圈选要素查询表数据
      }
    },
    watch: {
      allRadioIndexData: {//全部序号列表
        handler: function(newVal,oldVal){
          if(newVal!=oldVal){
            this.allRadioIndexList = newVal;
            //根据全部序号列表设置全部查询图层数组
            this.addAllBaseVectorLayerArray();
            //根据全部序号列表设置全部超图图层数组
            this.addAllRestVectorLayerArray();
          }
        },
        immediate:true
      },
      allListData: {
        handler: function(newVal,oldVal){
          this.allDataList = newVal;
          if(newVal!=oldVal){
            this.showAllListData();
          }
        },
        immediate:true
      },
      typeCodeDataList: {//选择图层的版本号数据列表
        handler: function(newVal,oldVal){
          if(newVal!=oldVal){
            this.typeCodeDataArray = newVal;
            console.log("typeCodeDataList");
            console.log(newVal);
          }
        },
        immediate:true
      },
      resetClearAllBool: {//是否重置清空全部图层数组
        handler: function(newVal,oldVal){
          if(newVal==true){
            //重置清空全部图层数组
            this.resetClearAllEvent();
            //重置清空全部超图图层数组
            this.resetClearAllRestLayerEvent();
          }
        },
        immediate:true
      },
      dataTypeInfoArray:{//图层数据类型数组
        handler: function(newVal,oldVal){
          if(newVal!=oldVal){
            this.allDataTypeInfoArray = newVal;//全部超图图层信息数组
          }
        },
        immediate:true
      },
      mapDrawType: {//是否开启地图圈选查询
        handler: function(newVal,oldVal){
          if(newVal!=oldVal){
            console.log("是否开启地图圈选查询"+newVal);
            this.queryMapDrawType = newVal;
            this.queryMapEvent();
          }
        },
        immediate:true
      },
      allDrawGeomText: {//地图圈选空间数据
        handler: function(newVal,oldVal){
          if(newVal!=oldVal){
            console.log("地图圈选空间数据");
            console.log(newVal);
            this.drawGeomText = newVal;
          }
        },
        immediate:true
      },
      circleForm: {//地图圈选查询选择表类型
        handler: function(newVal,oldVal){
          console.log("地图圈选查询选择表类型");
          console.log(newVal);
          this.circleFormObj = newVal;
        },
        immediate:true
      },
      tableData: {//地图圈选查询数据结果
        handler: function(newVal,oldVal){
          console.log("地图圈选查询数据结果高亮显示图层");
          console.log(newVal);
          this.tableDataList = newVal;
          //地图圈选查询数据结果高亮显示图层
          this.showTableDataLayer();
        },
        immediate:true
      },
    },
    created() {

    },
    mounted() {
      console.log("mounted");
      let that = this;
      //地图异步加载
      this.$nextTick(function(){
        console.log('地图异步加载');
        //地图异步加载
        setTimeout(() => {
          //初始化地图信息
          that.initMap();
          //显示全部超图图层
          // that.showAllLayer(0);
          //获取历史设定地震点统计总数
          // that.getAllFeatureCount();
        }, 200);
      });
    },
    beforeCreate() {//生命周期创建之前
      console.log("beforeCreate");
    },
    beforeMount() {//生命周期挂载之前
      console.log("beforeMount");
    },
    beforeUpdate() {//生命周期更新之前
      console.log("beforeUpdate");
    },
    updated() {//生命周期更新之后
      console.log("updated");
    },
    beforeDestroy() {//生命周期销毁之前
      console.log("beforeDestroy");
    },
    destroyed() {//生命周期销毁完成
      this.map = null;
      console.log("销毁地图");
    },
    activated() {//如果页面有keep-alive缓存功能激活，这个函数会触发
      console.log("activated-"+this.str);
      //自动获取地图div高度
      this.autodivheight();
      //浏览器窗口发生变化时同时变化DIV高度
      window.onresize=this.autodivheight;
    },
    deactivated() {//如果页面有keep-alive缓存功能停用，这个函数会触发
      console.log("deactivated-"+this.str);
      //取消浏览器窗口发生变化时同时变化DIV高度事件
      window.onresize = null;
    },
    methods: {
      initMap() {
        debugger;
        let that = this;
        let mapStr = this.str;
        let targetMap = document.getElementById(mapStr+"-map");
        if(targetMap.innerHTML!=""){
          console.log("清空targetMap");
        }
        targetMap.innerHTML = "";//清空
        //新建popup弹窗
        let targetDiv = document.getElementById(mapStr+"-mapDiv");
        let node = document.createElement("div");
        node.id = mapStr+"-popup";
        node.setAttribute("class","new-ol-popup");
        node.innerHTML = '<a href="#" id="'+mapStr+'-popup-closer" class="new-ol-popup-closer"></a>' +
                '<div id="'+mapStr+'-popup-content"></div>';
        targetDiv.appendChild(node);
        console.log("新建popup");
        //自动获取地图div高度
        this.autodivheight();
        //浏览器窗口发生变化时同时变化DIV高度
        window.onresize=this.autodivheight;
        if(this.map){//避免重复加载地图
          console.log("避免重复加载地图");
          return;
        }
        console.log("初始化地图");
        //获取投影4490坐标系
        this.projection4490 = getProjection();
        //初始化地图信息
        this.map = new Map({
          target: targetMap.id,
          /*controls: defaultControls({attributionOptions: {collapsed: false}})
              .extend([new Logo()]),*/
          view: new View({
            center: this.center,
            maxZoom: 18,
            minZoom: 4,
            zoom: this.zoom,
            constrainResolution:true,//缩放地图可移动到最近的缩放级别（整数zoom级别）
            projection: 'EPSG:4490',
            // resolutions:getResolutions()
          })
        });
        console.log("this.map");
        console.log(this.map);
        //添加天地图图层
        this.layer1 = getTiandituVecMap();//fxpc天地图街道影像底图
        this.map.addLayer(this.layer1);
        this.layer2 = getTiandituVecText();//fxpc天地图街道地图注记
        this.map.addLayer(this.layer2);
        this.layer1.setZIndex(0);
        this.layer2.setZIndex(0);
        //矢量绘制图层
        this.source = new VectorSource({
          wrapX: false
        });
        let vectorLayer = new VectorLayer({
          source: that.source,
          projection: 'EPSG:4490'
        });
        this.map.addLayer(vectorLayer);
        vectorLayer.setZIndex(1);
        //测量结果图层
        this.measureSource = new VectorSource({
          wrapX: false
        });
        let measureLayer = new VectorLayer({
          source: that.measureSource,
          projection: 'EPSG:4490'
        });
        this.map.addLayer(measureLayer);
        measureLayer.setZIndex(1);

        //选中要素高亮显示图层
        this.selectFeatureLayer = new VectorLayer({
          source: new VectorSource({
            wrapX: false
          }),
          projection: 'EPSG:4490'
        });
        this.map.addLayer(this.selectFeatureLayer);
        this.selectFeatureLayer.setZIndex(50);

        //地图圈选要素高亮显示图层
        this.queryFeatureLayer = new VectorLayer({
          source: new VectorSource({
            wrapX: false
          }),
          projection: 'EPSG:4490'
        });
        this.map.addLayer(this.queryFeatureLayer);
        this.queryFeatureLayer.setZIndex(50);

        //添加控件
        let info = new Control({element: document.getElementById(mapStr+'-mapDiv')});
        info.setMap(this.map);
        this.map.addControl(info);
        //比例尺控件
        // let scaleControl = new ScaleLine();
        // this.map.addControl(scaleControl);
        //弹出窗口
        let popupTarget = document.getElementById(this.str+"-popup");
        if(popupTarget){
          this.popupInfoLayer = new Overlay({
            element: popupTarget,
            positioning: 'center-center'
          });
          this.map.addOverlay(this.popupInfoLayer);
          //显示弹出窗口
          document.getElementById(this.str+"-popup").style.display="block";
          //关闭弹出事件
          document.getElementById(this.str+"-popup-closer").onclick = function () {
            that.popupInfoLayer.setPosition(undefined);
            //隐藏弹出窗口
            document.getElementById(that.str+"-popup").style.display="none";
          };
        }
        //右键菜单弹出窗口
        let contextmenuTarget = document.getElementById(this.str+"-contextmenu");
        if(contextmenuTarget){
          this.contextmenuLayer = new Overlay({
            element: contextmenuTarget,
            positioning: 'center-center'
          });
          this.map.addOverlay(this.contextmenuLayer);
          //显示右键菜单
          document.getElementById(that.str+"-contextmenu").style.display="block";
        }
        //右键菜单事件
        this.map.on('contextmenu', function(event){
          event.preventDefault();//屏蔽自带的右键事件
          let pixel = that.map.getEventPixel(event.originalEvent);
          let coordinate = that.map.getEventCoordinate(event.originalEvent);
          //根据经纬度查询当前显示的图层要素数据
          // that.getAllShowLayerFeatureDataByLonLat(coordinate);

          //显示右键菜单
          // that.contextmenuLayer.setOffset([10,-30]);
          // that.contextmenuLayer.setPosition(coordinate);

          let feature = that.map.forEachFeatureAtPixel(pixel,function(feature){
            //根据像素坐标获取右键选中的地图要素
            return feature;
          });
          if(feature && that.draw==null){

          }
        });
        //点击地图事件
        this.map.on('click', function(event){
          //隐藏右键菜单
          that.hideContextMenu();
          //隐藏弹出窗口
          if(that.popupInfoLayer!=null){
            that.popupInfoLayer.setPosition(undefined);
          }
          //隐藏右键菜单窗口
          if(that.contextmenuLayer!=null){
            that.contextmenuLayer.setPosition(undefined);
          }
          let pixel = that.map.getEventPixel(event.originalEvent);
          let coordinate = that.map.getEventCoordinate(event.originalEvent);
          //判断定位工具是否开启状态
          if(that.showHidePositionTool==false){
            document.getElementById(mapStr+"-MousePositionLon").value = coordinate[0];
            document.getElementById(mapStr+"-MousePositionLat").value = coordinate[1];
          }
          //清空选中要素高亮显示图层
          that.selectFeatureLayer.getSource().clear();
          //根据经纬度查询当前显示的图层要素数据
          that.getAllShowLayerFeatureDataByLonLat(coordinate);

          let feature = that.map.forEachFeatureAtPixel(pixel,function(feature){
            //根据像素坐标获取右键选中的地图要素
            return feature;
          });
          if(feature && that.draw==null){
            //选中要素
            that.selectFeature = feature;
            /*//要素属性
            let temp = feature.getProperties();
            console.log(temp);
            if(temp.typeCode!=undefined && temp.typeCode!=null && temp.id!=undefined && temp.id!=null){
              if(feature.getProperties().layerName) {
                //根据图层名称获取序号
                let layerName = feature.getProperties().layerName.split("#")[0];
                //获取数据类型信息
                let dataTypeInfo = that.getDataTypeInfo(layerName,"table");
                if (dataTypeInfo != null) {
                  //主键ID
                  let fieldId = dataTypeInfo.fieldId;
                  let selectedId = feature.getProperties().attributes[fieldId];
                  let radioLabel = dataTypeInfo.radioLabel;
                  let versionCode = feature.getProperties().attributes["data_version"];
                  //根据图层序号和版本号获取图层序号
                  that.selectLayerIndex = that.getRestVectorLayerIndexArray(radioLabel,versionCode);
                  if(that.selectLayerIndex!=null && that.selectLayerIndex.length==2){
                    let iIndex = that.selectLayerIndex[0];
                    let jIndex = that.selectLayerIndex[1];
                    //矢量切片样式
                    if(that.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles){
                      that.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles.featureSelectedFunction({
                        selectedId: selectedId,
                        layerName: feature.getProperties().layerName,
                        fieldId:fieldId
                      });
                      if(that.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer){
                        that.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer.changed();
                      }
                    }
                  }
                }
              }
              let typeCode = temp.typeCode;
              let id = temp.id;
              that.$emit("getDetailDataById",temp);
            }*/
          }
        });
        //地图移动事件
        this.map.on('moveend', function (event) {
          let center = that.map.getView().getCenter();
          let zoom = that.map.getView().getZoom();
          if(center[0]!=that.center[0] || center[1]!=that.center[1] || zoom!=that.zoom){
            //设置主界面图标文字
            that.zoomDefaultPositionBool = false;
          }else{//主界面
            //设置主界面图标文字
            that.zoomDefaultPositionBool = true;
          }
        });
        //鼠标移动事件--测量工具
        this.map.on('pointermove', function (evt) {
          if (evt.dragging) {
            return;
          }
          if(that.measure!=null){
            let helpMsg = '点击开始绘制';

            if (that.sketch) {
              const geom = that.sketch.getGeometry();
              if (geom instanceof Polygon) {
                helpMsg = '点击继续绘制多边形';
              } else if (geom instanceof LineString) {
                helpMsg = '点击继续绘制折线';
              }
            }

            that.helpTooltipElement.innerHTML = helpMsg;
            that.helpTooltip.setPosition(evt.coordinate);

            that.helpTooltipElement.classList.remove('hidden');
          }
        });
        //鼠标移出事件--测量工具
        this.map.getViewport().addEventListener('mouseout', function () {
          if(that.measure!=null){
            that.helpTooltipElement.classList.add('hidden');
          }
        });
        //地址匹配
        //this.addressMatchService = new AddressMatchService(this.addressUrl);
        //地图缩放到权限位置
        this.zoomDefaultPosition();
      },
      autodivheight() {//自动获取div高度
        //获取浏览器窗口高度
        let winHeight = 0;
        if (window.innerHeight) {
          winHeight = window.innerHeight;
        } else if ((document.body) && (document.body.clientHeight)) {
          winHeight = document.body.clientHeight;
        }
        //通过深入Document内部对body进行检测，获取浏览器窗口高度
        if (document.documentElement && document.documentElement.clientHeight) {
          winHeight = document.documentElement.clientHeight;
        }
        //全屏时窗口高度:864px,地图div高度:754px
        let tempHeight = 864;
        let mapTempHeight = 754;
        let mapHeight = winHeight - tempHeight + mapTempHeight;
        //最小高度
        if(mapHeight<480){
          mapHeight = 480;
        }
        //设置地图高度
        document.getElementById(this.str+"-map").style.height= mapHeight +"px";
        console.log("窗口高度："+winHeight+"地图高度："+mapHeight);
        //resize事件--刷新地图,确保地图不变形
        if(this.map){
          this.map.updateSize();
          console.log("resize事件--刷新地图,确保地图不变形");
        }
      },
      setPopupContent(html){//设置弹窗内容
        document.getElementById(this.str+'-popup-content').innerHTML = html;
        //显示弹出窗口
        document.getElementById(this.str+"-popup").style.display="block";
      },
      getTextFormat(str){//格式化文本内容
        if(str==null || str==undefined){
          str = "";
        }
        return str;
      },
      hideContextMenu(){//隐藏右键菜单
        //隐藏右键菜单

      },
      //切换地图
      switchMap(){
        if(this.switchMapBool){//显示街道图
          this.switchMapBool = false;
          //添加天地图图层
          if(this.layer1==null){
            this.layer1 = getTiandituVecMap();//fxpc天地图街道影像底图
            this.map.addLayer(this.layer1);
          }
          if(this.layer2==null){
            this.layer2 = getTiandituVecText();//fxpc天地图街道地图注记
            this.map.addLayer(this.layer2);
          }
          //显示街道图
          this.layer1.setVisible(true);
          this.layer2.setVisible(true);
          this.layer3.setVisible(false);
          this.layer4.setVisible(false);
          this.layer1.setZIndex(0);
          this.layer2.setZIndex(0);
        }else{//显示卫星图
          this.switchMapBool = true;
          if(this.layer3==null){
            this.layer3 = getTiandituImgMap();//fxpc天地图卫星影像底图
            this.map.addLayer(this.layer3);
          }
          if(this.layer4==null){
            this.layer4 = getTiandituImgText();//fxpc天地图卫星影像注记
            this.map.addLayer(this.layer4);
          }
          //显示卫星图
          this.layer1.setVisible(false);
          this.layer2.setVisible(false);
          this.layer3.setVisible(true);
          this.layer4.setVisible(true);
          this.layer3.setZIndex(0);
          this.layer4.setZIndex(0);
        }
      },
      //地图缩放到权限位置
      zoomDefaultPosition() {
        //刷新地图,确保地图不变形
        this.map.updateSize();
        this.map.getView().setCenter(this.center);
        this.map.getView().setZoom(this.zoom);
        this.zoomDefaultPositionBool = true;
      },
      //显示工具箱
      showHideToolsBoxDiv(){
        if(this.showHideToolsBox){
          this.showHideToolsBox = false;
          document.getElementById(this.str+"-ToolsBoxDiv").style.display="block";
        }else{
          this.showHideToolsBox = true;
          document.getElementById(this.str+"-ToolsBoxDiv").style.display="none";
        }
        //关闭全部工具
        this.closeAllToolsBox(null);
      },
      //关闭全部工具
      closeAllToolsBox(type){
        //关闭测量工具
        if(type!="MeasureTool" && this.showHideMeasureTool==false){
          this.showHideMeasureTool = true;
          let divId = this.str+"-MeasureToolsDiv";
          //隐藏
          document.getElementById(divId).style.display = "none";
          //清空测量结果
          this.clearMeasure();
          this.clearMeasureBool = true;
        }
        //关闭定位工具
        if(type!="PositionTool" && this.showHidePositionTool==false){
          this.showHidePositionTool = true;
          let divId = this.str+"-MousePositionDiv";
          //隐藏
          document.getElementById(divId).style.display = "none";
          //清空定位结果
          this.clearPosition();
        }
      },
      //地图工具--测试地图打印功能
      toolsBoxPrintTest(){
        let that = this;
        //测试地图导出方法一
        /*this.map.once('rendercomplete', function () {
          const mapCanvas = document.createElement('canvas');
          const size = that.map.getSize();
          mapCanvas.width = size[0];
          mapCanvas.height = size[1];
          const mapContext = mapCanvas.getContext('2d');
          Array.prototype.forEach.call(
              //document.querySelectorAll('.ol-layer canvas'),
              document.querySelectorAll('#indexMap-map .ol-viewport .ol-layer canvas'),
              function (canvas) {
                if (canvas.width > 0) {
                  const opacity = canvas.parentNode.style.opacity;
                  mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity);
                  const transform = canvas.style.transform;
                  // Get the transform parameters from the style's transform matrix
                  const matrix = transform
                      .match(/^matrix\(([^\(]*)\)$/)[1]
                      .split(',')
                      .map(Number);
                  // Apply the transform to the export map context
                  CanvasRenderingContext2D.prototype.setTransform.apply(
                      mapContext,
                      matrix
                  );
                  mapContext.drawImage(canvas, 0, 0);
                }
              }
          );
          if (navigator.msSaveBlob) {
            // link download attribute does not work on MS browsers
            navigator.msSaveBlob(mapCanvas.msToBlob(), 'map.png');
          } else {
            const link = document.getElementById('image-download');
            link.crossOrigin = 'anonymous';
            link.href = mapCanvas.toDataURL();
            link.click();
          }
        });
        this.map.renderSync();*/


        //测试地图导出方法二
        /*let exportPNGElement = document.getElementById('export-png'); //导出图片功能项
        let manypng = document.getElementById('manypng'); //导出图片功能项
        if ('download' in exportPNGElement) {
          exportPNGElement.addEventListener('click', function (e) {
            that.map.once('postcompose', function (event) {debugger
              let canvas = event.context.canvas; //地图渲染容器
              exportPNGElement.href = canvas.toDataURL('image/png'); //导出图片
            });
            that.map.renderSync();
          }, false);
        } else {
          alert("浏览器不支持此导出地图图片功能！");
        }

        if ('download' in manypng) {
          manypng.addEventListener('click', function(e) {
            //  that.map.removeInteraction(draw);
            addInteraction();
            that.map.renderSync();
          },false);
        }

        let draw; // global so we can remove it later
        let source = new VectorSource();
        function addInteraction() {
          draw = new Draw({
            source: source,
            type: 'LineString',
            style: new Style({
              fill: new Fill({
                color: 'rgba(255, 255, 255, 0.2)'
              }),
              stroke: new Stroke({
                color: '#ffcc33',
                width: 2
              }),
              image: new CircleStyle({
                radius: 7,
                fill: new Fill({
                  color: '#ffcc33'
                })
              })
            }),
            maxPoints: 2,
            geometryFunction: createBox()//矩形框
          })

          that.map.addInteraction(draw);

          // that.map.values_.target='map2';

          function getXDis(e, number) {
            let min = undefined;
            let max = undefined;
            e.forEach(element => {
              if (min == undefined || element[number] < min) {
                min = element[number];
              }

              if (max == undefined || element[number] > max) {
                max = element[number];
              }
            });
            return [min+2, max - min-4];
          }

          let extent = [];
          draw.on('drawend',function(evt){
            let feature = evt.feature;console.log(feature);
            let ftarget = evt.target.a;
            let geometry=feature.getGeometry();
            let ext=geometry.getExtent();
            that.map.removeInteraction(draw);

            let r = that.map.getView().getResolutionForExtent(ext, that.map.getSize());//根据范围获取分辨率
            that.map.getView().setResolution(r);
            that.map.getView().setZoom(12);
            let centerone=olExtent.getCenter(ext);
            that.map.getView().setCenter(centerone);

            let canvas;
            let imageData;
            let canvas2;
            let coordinate=geometry.getCoordinates();
            that.map.once("postrender", function (e) {
              extent[0] = e.target.getPixelFromCoordinate(coordinate[0][0]);//转画布坐标
              extent[1] = e.target.getPixelFromCoordinate(coordinate[0][1]);
              extent[2] = e.target.getPixelFromCoordinate(coordinate[0][2]);
              extent[3] = e.target.getPixelFromCoordinate(coordinate[0][3]);

              let x_dx = getXDis(extent, 0);
              let y_dy = getXDis(extent, 1);

              that.map.once("postcompose", function(event) {
                canvas = event.context.canvas;
                let ctx2=canvas.getContext("2d");
                imageData = ctx2.getImageData(x_dx[0], y_dy[0], x_dx[1], y_dy[1]);
                let c=document.getElementById("indexMap-map");
                c.style.width=imageData.width+'px';
                c.style.height=imageData.height+'px';
                that.map.updateSize();//容器改变重新加载地图
              });
              that.map.once('rendercomplete',function(){//渲染完成
                canvas.toBlob(function (blob) {
                  saveAs(blob, 'map.png');debugger
                  $('#indexMap-map').css({
                    width:"100%",
                    height:"100%"
                  });
                  that.map.updateSize();//容器改变重新加载地图
                });
              });
            });
          });
        }*/
      },
      measureToolBox(){//测量工具Div
        let divId = this.str+"-MeasureToolsDiv";
        //关闭全部工具
        this.closeAllToolsBox("MeasureTool");
        if(this.showHideMeasureTool){
          this.showHideMeasureTool = false;
          //显示
          document.getElementById(divId).style.display = "block";
        }else{
          this.showHideMeasureTool = true;
          //隐藏
          document.getElementById(divId).style.display = "none";
        }
      },
      measureDistance(){//测距
        if(this.source!=null){
          //地图工具箱--开启测距
          this.setMapToolBox('MeasureDistance');
          //设置样式
          this.measureDistanceBool = false;
          this.measureAreaBool = true;
          this.stopMeasureBool = true;
          this.clearMeasureBool = true;
        }
      },
      measureArea(){//测面
        if(this.source!=null){
          //地图工具箱--开启测面
          this.setMapToolBox('MeasureArea');
          //设置样式
          this.measureAreaBool = false;
          this.measureDistanceBool = true;
          this.stopMeasureBool = true;
          this.clearMeasureBool = true;
        }
      },
      stopMeasure(){//停止测量
        if(this.source!=null){
          //地图工具箱--停止测量
          this.setMapToolBox('StopMeasure');
          //设置样式
          this.stopMeasureBool = false;
          this.measureDistanceBool = true;
          this.measureAreaBool = true;
          this.clearMeasureBool = true;
        }
      },
      clearMeasure(){//清空测量结果
        if(this.source!=null){
          //地图工具箱--清空测量结果
          this.setMapToolBox('ClearMeasure');
          //设置样式
          this.clearMeasureBool = false;
          this.measureDistanceBool = true;
          this.measureAreaBool = true;
          this.stopMeasureBool = true;
        }
      },
      positionToolBox(){//定位工具Div
        let divId = this.str+"-MousePositionDiv";
        //关闭全部工具
        this.closeAllToolsBox("PositionTool");
        if(this.showHidePositionTool){
          this.showHidePositionTool = false;
          //显示
          document.getElementById(divId).style.display = "block";
        }else{
          this.showHidePositionTool = true;
          //隐藏
          document.getElementById(divId).style.display = "none";
        }
      },
      addPosition(){//添加定位结果
        this.clearPositionBool = true;
        this.addPositionBool = false;
        //添加定位结果
        if(this.source!=null){
          let longitude = document.getElementById(this.str+"-MousePositionLon").value;
          let latitude = document.getElementById(this.str+"-MousePositionLat").value;
          //处理经纬度
          let lonlat = this.getLonLat(longitude,latitude);
          if(lonlat!=null){
            //点
            let featureTmp = new Feature({
              geometry: new Point(lonlat)
            });
            //样式
            let style = this.getPointStyle();
            featureTmp.setStyle(style);
            //设置属性
            featureTmp.setProperties({
              type:"position",
              longitude:longitude,
              latitude:latitude,
            });
            //添加定位点
            this.source.addFeature(featureTmp);
            //居中缩放
            this.map.getView().setCenter(lonlat);
            this.map.getView().setZoom(12);
          }
        }
      },
      clearPosition(){//清空定位结果
        this.clearPositionBool = false;
        this.addPositionBool = true;
        //地图工具箱--清空
        this.setMapToolBox("Clear");
      },
      //地图工具箱
      setMapToolBox(value){
        let that = this;
        if (value === 'Clear') {//清空
          //清空
          that.source.clear();
          //停止绘制|修改|拖拽|选择
          clearInteraction();
        }else if (value === 'Point' || value === 'LineString' || value === 'Polygon' || value === 'Circle' || value==='Rectangle') {//开启绘制
          //点|线|面|圆绘制
          //开启绘制
          startDrawInteraction(value,false);
        }else if (value === 'FreeHandLineString' || value === 'FreeHandPolygon') {//开启绘制
          //手绘线|手绘面
          value = value.split("FreeHand")[1];
          //开启绘制
          startDrawInteraction(value,true);
        }else if (value === 'StopDraw') {//停止绘制
          //停止绘制
          stopDrawInteraction();
        }else if (value === 'Snap') {//开启捕捉
          //开启捕捉
          startSnapInteraction();
        }else if (value === 'NotSnap') {//停止捕捉
          //停止捕捉
          stopSnapInteraction();
        }else if (value === 'Modify') {//开启修改
          //开启修改
          startModifyInteraction();
        }else if (value === 'NotModify') {//停止修改
          //停止修改
          stopModifyInteraction();
          //停止选择
          stopSelectInteraction();
        }else if (value === 'Drag') {//开启拖拽
          //开启拖拽
          startDragInteraction();
        }else if (value === 'NotDrag') {//停止拖拽
          //停止拖拽
          stopDragInteraction();
        }else if (value === 'Select') {//开启选择
          //开启选择
          startSelectInteraction();
        }else if (value === 'NotSelect') {//停止选择
          //停止选择
          stopSelectInteraction();
        } else if (value === 'MeasureDistance') {//开启测距
          //开启测距
          startMeasureInteraction('LineString');
        } else if (value === 'MeasureArea') {//开启测面
          //开启测面
          startMeasureInteraction('Polygon');
        } else if (value === 'StopMeasure') {//停止测量（测距|测面）
          //停止测量
          stopMeasureInteraction();
        } else if (value === 'ClearMeasure') {//清空测量结果
          //停止测量
          stopMeasureInteraction();
          //清空测量结果
          clearMeasureResult();
        }

        //停止绘制|修改|拖拽|选择
        function clearInteraction() {
          //停止拖拽
          stopDragInteraction();
          //停止修改
          stopModifyInteraction();
          //停止选择
          stopSelectInteraction();
          //停止绘制
          stopDrawInteraction();
        }

        //停止捕捉
        function stopSnapInteraction(){
          if (that.snap) {
            that.map.removeInteraction(that.snap);
            that.snap = null;
          }
        }

        //开启捕捉
        function startSnapInteraction(){
          //停止捕捉
          stopSnapInteraction();
          //开启捕捉
          that.snap = new Snap({
            source: that.source
          });
          that.map.addInteraction(that.snap);
        }

        //停止拖拽
        function stopDragInteraction() {
          //停止拖拽
          if (that.drag) {
            that.map.removeInteraction(that.drag);
            that.drag = null;
          }
        }

        //开启拖拽
        function startDragInteraction() {
          //停止绘制
          stopDrawInteraction();
          //停止修改
          stopModifyInteraction();
          //开启选择
          startSelectInteraction();
          //停止拖拽
          stopDragInteraction();
          //开启拖拽
          that.drag = new Translate({
            features: that.select.getFeatures()
          });
          that.map.addInteraction(that.drag);
        }

        //停止修改
        function stopModifyInteraction() {
          //停止修改
          if (that.modify) {
            that.map.removeInteraction(that.modify);
            that.modify = null;
          }
        }

        //开启修改
        function startModifyInteraction() {
          //停止绘制
          stopDrawInteraction();
          //开启选择
          startSelectInteraction();
          //停止修改
          stopModifyInteraction();
          //开启修改
          that.modify = new Modify({
            features: that.select.getFeatures()
          });
          that.map.addInteraction(that.modify);
        }

        //停止选择
        function stopSelectInteraction() {
          //停止选择
          if (that.select) {
            that.map.removeInteraction(that.select);
            that.select = null;
          }
        }

        //开启选择
        function startSelectInteraction() {
          //停止选择
          stopSelectInteraction();
          //开启选择
          that.select = new Select({
            wrapX: false
          });
          that.map.addInteraction(that.select);
        }

        //停止绘制
        function stopDrawInteraction() {
          //停止绘制
          if (that.draw) {
            that.map.removeInteraction(that.draw);
            that.draw = null;
          }
        }

        //开启绘制
        function startDrawInteraction(type,bool) {
          //停止拖拽
          stopDragInteraction();
          //停止修改
          stopModifyInteraction();
          //停止选择
          stopSelectInteraction();
          //停止绘制
          stopDrawInteraction();
          if(bool){//手绘线|手绘面
            that.draw = new Draw({
              source: that.source,
              type: type,
              snapTolerance: 20,
              freehand: true
            });
            that.map.addInteraction(that.draw);
          }else{//点|线|面|圆|矩形绘制
            if(type=="Rectangle"){
              drawRectangle();//绘制矩形
            }else{//点|线|面|圆绘制
              that.draw = new Draw({
                source: that.source,
                type: type,
                snapTolerance: 20
              });
              that.map.addInteraction(that.draw);
            }
          }
          //完成绘制事件
          that.draw.on('drawend', function (evt) {
            //是否开启地图圈选查询
            if(that.queryMapDrawType=="Polygon" || that.queryMapDrawType=="Rectangle"){
              //停止绘制
              stopDrawInteraction();
              evt.feature.setProperties({
                type:"draw",//类型
              });
              setTimeout(function(){
                //获取绘制数据进行分布规律分析
                that.getAllDrawGeomEmit();
              },100);
            }
          });
        }

        //计算面积
        function getPolygonArea (polygon) {
          // 这里一定要给坐标，和地图坐标保持一致，否则面积不准
          const area = getArea(polygon, {projection: 'EPSG:4490'})
          let output = Math.round((area / 1000000) * 100) / 100;//平方公里
          return output;
        }

        //绘制长方形
        function drawRectangle() {
          //设置maxPoints及geometryFunction
          let maxPoints, geometryFunction;
          maxPoints = 2;
          geometryFunction = function (coordinates, geometry) {
            if (!geometry) {//!geometry  意思是如果没有geometry则...
              geometry = new Polygon([[[0, 0], [-30, 0], [-10, 30], [0, 0]]]);//临时
            }
            //设置起始点及终止点
            let start = coordinates[0];
            let end = coordinates[1];
            geometry.setCoordinates([
              [start, [start[0], end[1]], end, [end[0], start[1]], start]     //特别注意，长方形终止点与起始点重合
            ]);
            return geometry;
          };
          //新建绘制长方形interaction
          that.draw = new Draw({
            source: that.source,
            type: "LineString",
            geometryFunction: geometryFunction,
            maxPoints: maxPoints
          });
          //将interaction添加到地图中
          that.map.addInteraction(that.draw);
          //完成绘制事件
          that.draw.on('drawend', function (evt) {
            //是否开启地图圈选查询
            if(that.queryMapDrawType=="Polygon" || that.queryMapDrawType=="Rectangle"){
              //停止绘制
              stopDrawInteraction();
              evt.feature.setProperties({
                type:"draw",//类型
              });
              setTimeout(function(){
                //获取绘制数据
                that.getAllDrawGeomEmit();
              },100);
            }
          });
        }

        ////////////////////////////////////////////////////////////////////测量工具箱
        //格式化距离
        function formatLength(line) {
          const length = getLength(line, {projection: 'EPSG:4490'});
          let output;
          if (length > 100) {
            output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km';
          } else {
            output = Math.round(length * 100) / 100 + ' ' + 'm';
          }
          return output;
        }

        //格式化面积
        function formatArea(polygon) {
          const area = getArea(polygon, {projection: 'EPSG:4490'});
          let output;
          if (area > 10000) {
            output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
          } else {
            output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
          }
          return output;
        }

        //创建新的提示tip
        function createHelpTooltip() {
          if (that.helpTooltipElement!=null) {
            that.helpTooltipElement.parentNode.removeChild(that.helpTooltipElement);
          }
          that.helpTooltipElement = document.createElement('div');
          that.helpTooltipElement.className = 'ol-tooltip hidden';
          that.helpTooltip = new Overlay({
            element: that.helpTooltipElement,
            offset: [15, 0],
            positioning: 'center-left',
          });
          that.map.addOverlay(that.helpTooltip);
        }

        //创建新的测量提示
        function createMeasureTooltip() {
          if (that.measureTooltipElement!=null) {
            that.measureTooltipElement.parentNode.removeChild(that.measureTooltipElement);
          }
          that.measureTooltipElement = document.createElement('div');
          that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
          that.measureTooltip = new Overlay({
            element: that.measureTooltipElement,
            offset: [0, -15],
            positioning: 'bottom-center',
            stopEvent: false,
            insertFirst: false,
          });
          that.map.addOverlay(that.measureTooltip);
        }

        //开启测量工具
        function startMeasureInteraction(type) {
          //停止测量工具
          stopMeasureInteraction();

          console.log(type);
          //开启测量工具--绘制
          that.measure = new Draw({
            source: that.measureSource,
            type: type,
            style: new Style({
              fill: new Fill({
                color: 'rgba(255, 255, 255, 0.2)',
              }),
              stroke: new Stroke({
                color: 'rgba(0, 0, 0, 0.5)',
                lineDash: [10, 10],
                width: 2,
              }),
              image: new CircleStyle({
                radius: 5,
                stroke: new Stroke({
                  color: 'rgba(0, 0, 0, 0.7)',
                }),
                fill: new Fill({
                  color: 'rgba(255, 255, 255, 0.2)',
                }),
              }),
            }),
          });
          that.map.addInteraction(that.measure);

          //创建新的测量提示
          createMeasureTooltip();
          //创建新的提示tip
          createHelpTooltip();

          let listener;
          that.measure.on('drawstart', function (evt) {
            //设置sketch
            that.sketch = evt.feature;

            let tooltipCoord = evt.coordinate;

            listener = that.sketch.getGeometry().on('change', function (evt) {
              const geom = evt.target;
              let output;
              if (geom instanceof Polygon) {
                output = formatArea(geom);
                tooltipCoord = geom.getInteriorPoint().getCoordinates();
              } else if (geom instanceof LineString) {
                output = formatLength(geom);
                tooltipCoord = geom.getLastCoordinate();
              }
              that.measureTooltipElement.innerHTML = output;
              that.measureTooltip.setPosition(tooltipCoord);
            });
          });
          //完成测量绘制
          that.measure.on('drawend', function () {
            that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
            that.measureTooltip.setOffset([0, -7]);
            //添加到数组
            that.measureTooltipArray.push(that.helpTooltip);
            //添加到数组
            that.measureTooltipArray.push(that.measureTooltip);
            //清空sketch
            that.sketch = null;
            //清空tooltip
            that.measureTooltipElement = null;
            createMeasureTooltip();
            unByKey(listener);
          });
        }

        //停止测量工具
        function stopMeasureInteraction() {
          //停止绘制
          stopDrawInteraction();
          //停止测量工具
          if (that.measure) {
            that.map.removeInteraction(that.measure);
            that.measure = null;
            //隐藏提示tip
            that.helpTooltipElement.classList.add('hidden');
            //移除测量提示
            if(that.helpTooltip!=null){
              that.map.removeOverlay(that.helpTooltip);
            }
            if(that.measureTooltip!=null){
              that.map.removeOverlay(that.measureTooltip);
            }
          }
        }

        //清空测量结果
        function clearMeasureResult(){
          if(that.measureSource!=null){
            //清空测量结果
            that.measureSource.clear();
            //清空测量结果提示数组
            if(that.measureTooltipArray.length>0){
              for(let i=0;i<that.measureTooltipArray.length;i++){
                that.map.removeOverlay(that.measureTooltipArray[i]);
              }
              that.measureTooltipArray = [];
            }
          }
        }
      },
      getPointStyle(){//点图标样式
        let style = new Style({
          image: new Icon({
            src: dingweiImg,
            anchor: [0.5, 1]
          }),
        });

        return style;
      },
      getPointStyleByColor(color){//点样式
        if(color==null || color===""){
          color = "#00ffff";
        }
        let style = new Style({
          image: new CircleStyle({
            radius: 5,
            fill: new Fill({
              color: "rgba(0,0,0,0)"
            }),
            stroke:new Stroke({//线
              width:2,//宽
              color:color
            })
          })
        });

        return style;
      },
      getLineStringStyle(color){//线样式
        let style = new Style({
          fill:new Fill({//填充样式
            color:"rgba(0,0,0,0)"
          }),
          stroke:new Stroke({//线
            width:2,//宽
            color:color
          })
        });

        return style;
      },
      getPolyonStyle(color){//多边形样式
        let style = new Style({
          fill:new Fill({//填充样式
            color:"rgba(0,0,0,0)"
          }),
          stroke:new Stroke({//描绘
            width:2,//宽
            color:color
          })
        });

        return style;
      },
      //处理经纬度
      getLonLat(longitude,latitude){
        let lonlat = null;
        if(longitude!=null && latitude!=null && longitude!="" && latitude!=""){
          let lon = Number(longitude);
          let lat = Number(latitude);
          if(lon>0 && lon<180 && lat>0 && lat<90){
            lonlat = [lon,lat];
          }
        }

        return lonlat;
      },
      //地图显示全部查询结果
      showAllListData(){
        let allDataList = this.allDataList;
        if(this.map!=null && allDataList!=null && allDataList.length==5){
          console.log("地图显示全部查询结果");
          let radioLabel = allDataList[0];
          let versionCode = allDataList[1];
          let resultList = allDataList[2];
          let bool = allDataList[3];//添加、移除版本号图层
          //根据图层序号和版本号设置图层数组并获取当前版本号图层
          let selectLayer = this.setBaseVectorLayer(radioLabel,versionCode,bool);
          if(selectLayer!=null){
            if(resultList!=null && resultList.length>0){
              //获取三级数据类别（数据表）code
              let typeCode = this.getDictItemCode(radioLabel);
              this.showDataList(typeCode,selectLayer,versionCode,resultList);//显示查询图层数据
            }else{
              //清空图层上的所有要素
              //selectLayer.getSource().clear();
            }
          }
          //超图图层
          //根据图层序号和版本号设置超图图层数组并获取当前版本号图层
          let selectRestLayer = this.setRestVectorLayer(radioLabel,versionCode,bool);
          if(selectRestLayer!=null){
            let params = {
              radioLabel:radioLabel,
              versionCode:versionCode,
              show:bool,
              sqlText:selectRestLayer.sqlText
              // sqlText:""
            }
            //根据查询图层信息参数查询并显示图层
            this.queryLayersByParams(params);
          }
        }
      },
      showDataList(typeCode,selectLayer,versionCode,list){//显示查询图层数据
        console.log("显示查询图层数据"+versionCode);
        if(selectLayer!=null){
          //selectLayer.getSource().clear();//清空
          if(list!=null && list.length>0){
            console.log("length"+list.length);
            //全部经纬度
            let allCoordinates = [];
            for(let i=0;i<list.length;i++){
              let id = this.getDataIdByType(typeCode,list[i]);//根据数据类型解析数据主键ID
              let geomText = list[i].geom;//空间数据wkt
              if(geomText!=null && geomText!=""){
                geomText = geomText.toUpperCase();//转换大写字母
                if(geomText.indexOf("POINT")!=-1 || geomText.indexOf("MULTIPOINT")!=-1 ||
                        geomText.indexOf("LINESTRING")!=-1 || geomText.indexOf("MULTILINESTRING")!=-1 ||
                        geomText.indexOf("POLYGON")!=-1 || geomText.indexOf("MULTIPOLYGON")!=-1) {//矢量数据
                  //空间数据
                  let featureTmp = new WKT().readFeature(geomText);
                  if(geomText.indexOf("POINT")!=-1 || geomText.indexOf("MULTIPOINT")!=-1){//点
                    //样式
                    let style = this.getPointStyle();
                    featureTmp.setStyle(style);
                  }else if(geomText.indexOf("LINESTRING")!=-1 || geomText.indexOf("MULTILINESTRING")!=-1){//线
                    //样式
                    let style = this.getLineStringStyle("blue");
                    featureTmp.setStyle(style);
                  }else if(geomText.indexOf("POLYGON")!=-1 || geomText.indexOf("MULTIPOLYGON")!=-1){//面
                    //样式
                    let style = this.getPolyonStyle("blue");
                    featureTmp.setStyle(style);
                  }
                  //设置属性
                  featureTmp.setProperties({
                    id:id,//主键ID
                    //versionCode:versionCode,//版本号
                    typeCode:typeCode,//三级数据类别（数据表）code
                  });
                  //添加矢量数据
                  selectLayer.getSource().addFeature(featureTmp);
                  //获取范围
                  let extent = featureTmp.getGeometry().getExtent();
                  if(extent.length==4){
                    //全部经纬度--左下角
                    allCoordinates.push([extent[0],extent[1]]);
                    //全部经纬度--右上角
                    allCoordinates.push([extent[2],extent[3]]);
                  }
                }
              }
            }
            this.showBoundingExtent(allCoordinates);//缩放到区域位置
          }
        }
      },
      showBoundingExtent(coordinates){//缩放到区域位置
        //console.log("缩放到区域位置");
        if (coordinates!=null && coordinates.length > 1) {
          const extent = boundingExtent(coordinates);
          //this.map.getView().fit(extent, {duration: 1000, padding: [50, 50, 50, 50]});
          this.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
          //获取默认位置
          this.center = this.map.getView().getCenter();
          this.zoom = this.map.getView().getZoom();
        }
      },
      //根据图层序号获取图层数组
      getSelectLayerArray(radioLabel){
        let selectLayerArray = null;//选择图层
        if(this.allRadioIndexList!=null && this.allRadioIndexList.length>0){
          for(let i=0;i<this.allRadioIndexList.length;i++){
            if(this.allRadioIndexList[i]==radioLabel){
              selectLayerArray = this.allBaseVectorLayerArray[i];
              break;
            }
          }
        }

        return selectLayerArray;
      },
      //根据版本号获取图层
      getSelectLayer(selectLayerArray,versionCode){
        let selectLayer = null;//选择图层
        if(selectLayerArray!=null && selectLayerArray.length>0){
          for(let i=0;i<selectLayerArray.length;i++){
            let temp = selectLayerArray[i].getProperties();
            if(temp.versionCode==versionCode){
              selectLayer = selectLayerArray[i];
              break;
            }
          }
        }

        return selectLayer;
      },
      //根据图层序号和版本号设置图层数组
      setBaseVectorLayer(radioLabel,versionCode,bool){
        let selectLayer = null;
        //根据图层序号获取图层数组
        let selectLayerArray = this.getSelectLayerArray(radioLabel);
        //根据版本号获取图层
        selectLayer = this.getSelectLayer(selectLayerArray,versionCode);
        if(bool){//添加图层
          if(selectLayer!=null){
            console.log("已有图层"+versionCode);
            return selectLayer;
          }
          console.log("创建图层"+versionCode);
          //创建图层
          selectLayer = new VectorLayer({
            source: new VectorSource({
              wrapX: false
            }),
            projection: 'EPSG:4490'
          });
          this.map.addLayer(selectLayer);
          selectLayer.setZIndex(4);
          selectLayer.setProperties({
            versionCode:versionCode,
          });
          //添加图层数组
          selectLayerArray.push(selectLayer);
        }else{//移除图层
          //根据版本号清除图层要素
          this.removeLayerDataByTypeCode(selectLayerArray,versionCode);
        }

        return selectLayer;
      },
      //根据版本号清除图层要素
      removeLayerDataByTypeCode(selectLayerArray,versionCode){
        //查找版本号图层
        let index = -1;
        if(selectLayerArray!=null && selectLayerArray.length>0){
          for(let i=0;i<selectLayerArray.length;i++){
            let temp = selectLayerArray[i].getProperties();
            if(temp.versionCode==versionCode){
              index = i;
              break;
            }
          }
        }
        if(index!=-1){
          //清空图层上的所有要素
          selectLayerArray[index].getSource().clear();
          //移除图层
          this.map.removeLayer(selectLayerArray[index]);
          //图层数组移除图层
          selectLayerArray.splice(index,1);
        }
      },
      //重置清空全部图层数组
      resetClearAllEvent(){
        console.log("重置清空全部图层数组");
        let list = this.allBaseVectorLayerArray;
        if(list!=null && list.length>0){
          for(let i=0;i<list.length;i++) {
            let selectLayerArray = this.allBaseVectorLayerArray[i];
            if(selectLayerArray!=null && selectLayerArray.length>0){
              for(let j=0;j<selectLayerArray.length;j++){
                //清空图层上的所有要素
                this.allBaseVectorLayerArray[i][j].getSource().clear();
                //移除图层
                this.map.removeLayer(this.allBaseVectorLayerArray[i][j]);
              }
            }
            //清空图层数组
            this.allBaseVectorLayerArray[i] = [];
          }
        }
      },
      //根据全部序号列表设置全部查询图层数组
      addAllBaseVectorLayerArray(){
        let allLayerArray = [];
        if(this.allRadioIndexList!=null && this.allRadioIndexList.length>0){
          for(let i=0;i<this.allRadioIndexList.length;i++){
            allLayerArray.push([]);
          }
        }
        this.allBaseVectorLayerArray = allLayerArray;
      },
      //获取三级数据类别（数据表）code
      getDictItemCode(radioLabel){
        let typeCode = null;
        let list = this.typeCodeDataArray;
        if(list!=null && list.length>0) {
          for (let i = 0; i < list.length; i++) {
            if (list[i].radioLabel==radioLabel) {
              typeCode = list[i].dictItemCode;
              break;
            }
          }
        }

        return typeCode;
      },
      getDataIdByType(typeCode,data){//根据数据类型解析数据主键ID
        let id = "";
        //超图ID
        id = "SmID";

        return id;
      },
      /////////////////////////////////////////////////////////////////////////////////////////超图图层服务start
      //REST图层查询
      createMapRestLayer(iIndex,jIndex,layerUrl,layerID,zIndex){//根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
        let that = this;
        console.log(iIndex+","+jIndex);
        //瓦片地图图层
        let mapService = new MapService(layerUrl);//根据超图REST图层获取图层信息
        mapService.getMapInfo(function (serviceResult) {
          if(serviceResult.result!=undefined){
            let mapJSONObj = serviceResult.result;
            //获取超图发布的REST图层
            //let options = TileSuperMapRest.optionsFromMapJSON(layerUrl, mapJSONObj);
            let layerName = mapJSONObj.name;//图层名称
            //获取图层范围
            let bounds = mapJSONObj.bounds;
            let left = bounds.left;
            let bottom = bounds.bottom;
            let right = bounds.right;
            let top = bounds.top;
            let origin = [left, top];//左上角
            let extent = [left, bottom, right, top];//图层范围
            //获取超图发布的REST图层（自定义比例尺）
            let layer = getRESTLayer(layerUrl,layerID,origin,extent,mapJSONObj,17);
            that.map.addLayer(layer);
            //设置图层叠加顺序
            layer.setZIndex(zIndex);
            //添加到REST图层数组
            that.allRestVectorLayerArray[iIndex][jIndex].restTileLayer = layer;
            if(layerID && layerID!==""){
              //设置临时图层ID
              that.allRestVectorLayerArray[iIndex][jIndex].tempLayerId = layerID;
            }
            // console.log("extent");
            // console.log(extent);
            //缩放到图层范围
            that.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
            //图层范围
            let bbox = extent.join(",");
            //图层显示名称
            let realName = that.allRestVectorLayerArray[iIndex][jIndex].name;
            //获取图例
            that.getLayerLegend(realName,layerUrl,bbox);//根据url获取图层图例信息
          }
        });
      },
      //临时图层SQL查询更新并获取瓦片图层REST
      deleteRestMapTempLayersSet(layerUrl,layerID){//删除超图临时图层
        let that = this;
        let url = encodeURI(layerUrl + "/tempLayersSet.rjson");
        //查询
        let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中
        //获取数据后的处理程序
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            if(obj.length>0){
              for(let i=0;i<obj.length;i++){
                let path = obj[i].path;
                if(layerID!=null && layerID!=""){//指定临时图层ID
                  if(obj[i].name==layerID){
                    that.deleteTempLayersSet(path);//删除超图临时图层
                    break;
                  }
                }else{//全部临时图层
                  that.deleteTempLayersSet(path);//删除超图临时图层
                }
              }
            }
          }
        };
      },
      deleteTempLayersSet(url){//删除超图临时图层
        url = encodeURI(url);
        let xhr = new XMLHttpRequest();//第一步：建立所需的对象
        xhr.open("DELETE", url, true);//第二步：打开连接  将请求参数写在url中
        xhr.send();//第三步：发送请求  将请求参数写在URL中
        // 获取数据后的处理程序
        xhr.onreadystatechange = function(){
          let readyState = xhr.readyState;
          if (readyState == 4){
            let status = xhr.status;
            let responseText =  xhr.responseText ;
            let result = JSON.parse(responseText);
            if(result.succeed){
              //that.$message({ message: '删除临时图层成功!', type: 'success' });
            }else{
              //that.$message({ message: '删除临时图层失败!', type: 'warning' });
            }
            xhr.onreadystatechange = function(){};
            xhr = null;
          }
        };
      },
      createRestMapTempLayersSet(iIndex,jIndex,layerUrl,zIndex,sqlText){//查询REST图层信息并创建新的临时图层
        let url = encodeURI(layerUrl +"/layers.rjson");
        let that = this;
        //查询REST图层信息
        let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中
        //获取数据后的处理程序
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            if(obj.length>0){
              if(sqlText!=null && sqlText!=""){
                for(let i=0;i<obj.length;i++){
                  let layers = obj[i].subLayers.layers;
                  for(let j=0;j<layers.length;j++){
                    layers[j].displayFilter = sqlText;//SQL查询过滤
                  }
                }
              }
              that.postTempLayersSet(iIndex,jIndex,layerUrl,zIndex,obj);//创建并获取超图临时图层
            }
          }
        };
      },
      postTempLayersSet(iIndex,jIndex,layerUrl,zIndex,obj){//创建并获取超图临时图层
        let that = this;
        let url = encodeURI(layerUrl+"/tempLayersSet.rjson");
        let entry = JSON.stringify(obj);
        let xhr = new XMLHttpRequest();//第一步：建立所需的对象
        xhr.open("POST", url, true);//第二步：打开连接  将请求参数写在url中
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        //获取数据后的处理程序
        xhr.onreadystatechange = function(){
          let readyState = xhr.readyState;
          if (readyState == 4){
            let status = xhr.status;
            let responseText =  xhr.responseText ;
            let result = JSON.parse(responseText);
            if(result.succeed){
              let layerID = result.newResourceID;
              let newResourceLocation = result.newResourceLocation;
              //that.$message({ message: '创建临时图层成功!', type: 'success' });
              //查询超图临时图层
              //that.getMapTempLayer(iIndex,jIndex,layerUrl,layerID,zIndex);
              //根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
              that.createMapRestLayer(iIndex,jIndex,layerUrl,layerID,zIndex);
            }else{
              //that.$message({ message: '创建临时图层失败!', type: 'warning' });
            }
            xhr.onreadystatechange = function(){};
            xhr = null;
          }
        };
        xhr.send(entry);//第三步：发送请求  将请求参数写在URL中
      },
      getMapTempLayer(iIndex,jIndex,layerUrl,layerID,zIndex){//查询超图临时图层
        let that = this;
        let url = encodeURI(layerUrl + "/tempLayersSet.rjson");
        //查询
        let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中
        //获取数据后的处理程序
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            if(obj.length>0){
              if(layerID!=null && layerID!=""){
                for(let i=0;i<obj.length;i++){
                  if(obj[i].name==layerID){
                    //根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
                    that.createMapRestLayer(iIndex,jIndex,layerUrl,layerID,zIndex);
                    break;
                  }
                }
              }else{
                layerID  = obj[0].name;//默认取第一个
                //根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
                that.createMapRestLayer(iIndex,jIndex,layerUrl,layerID,zIndex);
              }
              that.$message({ message: '查询成功!', type: 'success' });
            }else{
              that.$message({ message: '无查询结果!', type: 'warning' });
            }
          }
        };
      },
      queryTempLayersSetBySql(iIndex,jIndex,layerUrl,zIndex,sqlText) {//根据SQL条件筛选更新并查询超图临时图层信息
        let that = this;
        let url = encodeURI(layerUrl + "/tempLayersSet.rjson");
        //查询
        let httpRequest = new XMLHttpRequest();
        httpRequest.open('GET', url, true);
        httpRequest.send();
        //获取数据后的处理程序
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            if(obj.length>0){
              //let tempUrl = obj[0].path;
              let layerID  = obj[0].name;//默认选第一个临时图层
              //更新超图临时图层信息
              that.getPutTempLayersSet(iIndex,jIndex,layerUrl,layerID,zIndex,sqlText);
            }
          }
        };
      },
      getPutTempLayersSet(iIndex,jIndex,layerUrl,layerID,zIndex,sqlText){//更新超图临时图层信息
        let that = this;
        //查询
        let url = encodeURI(layerUrl+"/tempLayersSet/"+layerID+".rjson");
        //查询
        let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中
        //获取数据后的处理程序
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            if(obj.length>0){
              for(let i=0;i<obj.length;i++){
                let layers = obj[i].subLayers.layers;
                for(let j=0;j<layers.length;j++){
                  layers[j].displayFilter = sqlText;//SQL查询过滤
                }
              }
            }
            //更新超图临时图层信息
            that.putTempLayersSet(iIndex,jIndex,url,layerUrl,layerID,zIndex,obj);
          }
        };
      },
      putTempLayersSet(iIndex,jIndex,url,layerUrl,layerID,zIndex,obj){//更新超图临时图层信息，获取临时图层
        let that = this;
        let entry = JSON.stringify(obj);
        let xhr = new XMLHttpRequest();//第一步：建立所需的对象
        xhr.open("PUT", url, true);//第二步：打开连接  将请求参数写在url中
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        //获取数据后的处理程序
        xhr.onreadystatechange = function(){
          let readyState = xhr.readyState;
          if (readyState == 4){
            let status = xhr.status;
            let responseText =  xhr.responseText ;
            let result = JSON.parse(responseText);
            if(result.succeed){
              //that.$message({ message: '更新临时图层成功!', type: 'success' });
              //查询超图临时图层
              //that.getMapTempLayer(iIndex,jIndex,layerUrl,layerID,zIndex);
              //根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
              that.createMapRestLayer(iIndex,jIndex,layerUrl,layerID,zIndex);
            }else{
              //that.$message({ message: '更新临时图层失败!', type: 'warning' });
            }
            xhr.onreadystatechange = function(){};
            xhr = null;
          }
        };
        xhr.send(entry);//第三步：发送请求  将请求参数写在URL中
      },
      //获取数据类型信息
      getDataTypeInfo(value,type){
        let dataTypeInfo = null;
        if(value && type && this.allDataTypeInfoArray!=null && this.allDataTypeInfoArray.length>0){
          for(let i=0;i<this.allDataTypeInfoArray.length;i++){
            if(this.allDataTypeInfoArray[i][type]===value){
              dataTypeInfo = this.allDataTypeInfoArray[i];
              break;
            }
          }
        }

        return dataTypeInfo;
      },
      addAllRestVectorLayerArray(){//全部超图图层数组
        let allLayerArray = [];
        if(this.allRadioIndexList!=null && this.allRadioIndexList.length>0){
          for(let i=0;i<this.allRadioIndexList.length;i++){
            allLayerArray.push([]);
          }
        }
        this.allRestVectorLayerArray = allLayerArray;
      },
      //根据图层序号获取超图图层数组
      getRestSelectLayerArray(radioLabel){
        let selectRestLayerArray = null;//选择图层
        if(this.allRadioIndexList!=null && this.allRadioIndexList.length>0){
          for(let i=0;i<this.allRadioIndexList.length;i++){
            if(this.allRadioIndexList[i]==radioLabel){
              selectRestLayerArray = this.allRestVectorLayerArray[i];
              break;
            }
          }
        }

        return selectRestLayerArray;
      },
      //根据版本号获取超图图层
      getRestSelectLayer(selectRestLayerArray,versionCode){
        let selectRestLayer = null;//选择图层
        if(versionCode && selectRestLayerArray!=null && selectRestLayerArray.length>0){
          for(let i=0;i<selectRestLayerArray.length;i++){
            let temp = selectRestLayerArray[i];
            if(temp.versionCode==versionCode){
              selectRestLayer = selectRestLayerArray[i];
              break;
            }
          }
        }

        return selectRestLayer;
      },
      //根据图层序号获取图层数组序号
      getRestLayerIndex(radioLabel){
        let index = null;
        if(radioLabel && this.allRestVectorLayerArray!=null && this.allRestVectorLayerArray.length>0) {
          for(let i=0;i<this.allRestVectorLayerArray.length;i++){
            if(this.allRadioIndexList[i]==radioLabel){
              index = i;
              break;
            }
          }
        }

        return index;
      },
      //根据图层序号和版本号获取图层序号
      getRestVectorLayerIndexArray(radioLabel,versionCode){
        let indexArray = [];
        if(radioLabel && versionCode && this.allRestVectorLayerArray!=null && this.allRestVectorLayerArray.length>0) {
          for(let i=0;i<this.allRestVectorLayerArray.length;i++){
            if(this.allRadioIndexList[i]==radioLabel){
              for(let j=0;j<this.allRestVectorLayerArray[i].length;j++){
                if(this.allRestVectorLayerArray[i][j].versionCode==versionCode){
                  indexArray = [i,j];
                }
              }
              break;
            }
          }
        }

        return indexArray;
      },
      //根据图层序号和版本号设置超图图层数组
      setRestVectorLayer(radioLabel,versionCode,bool){
        let selectLayer = null;
        //根据图层序号获取图层数组序号
        let iIndex = this.getRestLayerIndex(radioLabel);
        //根据图层序号和版本号获取图层序号
        let indexArray = this.getRestVectorLayerIndexArray(radioLabel,versionCode);
        let jIndex = null;
        if(indexArray!=null && indexArray.length==2){
          iIndex = indexArray[0];
          jIndex = indexArray[1];
          selectLayer = this.allRestVectorLayerArray[iIndex][jIndex];
        }
        console.log("iIndex"+iIndex+",jIndex"+jIndex);
        if(bool){//添加超图图层
          if(selectLayer!=null){
            console.log("已有超图图层"+versionCode);
            return selectLayer;
          }
          console.log("创建超图图层"+versionCode);
          //创建超图图层
          if(radioLabel && this.typeCodeDataArray!=null && this.typeCodeDataArray.length>0){
            for(let i=0;i<this.typeCodeDataArray.length;i++){
              if(this.typeCodeDataArray[i].radioLabel==radioLabel){
                let code = this.typeCodeDataArray[i].dictItemCode;
                let name = this.typeCodeDataArray[i].name;
                // let sqlText = "data_version like '%"+versionCode+"%'";//查询临时图层
                let sqlText = this.typeCodeDataArray[i].sqlFilter;//sql过滤条件
                selectLayer = {
                  code:code,//图层类型code
                  name:name,//图层名称
                  vectorTileLayer:null,//REST矢量切片图层
                  restTileLayer:null,//REST瓦片图层
                  sqlText:sqlText,//查询条件
                  tempLayerId:null,//临时图层ID
                  vectorTileStyles:null,//矢量切片样式
                  versionCode:versionCode,//版本号
                  radioLabel: radioLabel,//字典序号
                };
                break;
              }
            }
          }
          //添加超图图层数组
          this.allRestVectorLayerArray[iIndex].push(selectLayer);
          console.log("this.allRestVectorLayerArray--add");
          console.log(this.allRestVectorLayerArray);
        }else{//移除超图图层
          //根据版本号清除超图图层要素
          this.removeRestLayerDataByTypeCode(iIndex,jIndex);
        }

        return selectLayer;
      },
      //根据版本号清除超图图层要素
      removeRestLayerDataByTypeCode(iIndex,jIndex){
        if(iIndex!=null && jIndex!=null){
          //图层名称
          let realName = this.allRestVectorLayerArray[iIndex][jIndex].name;
          //移除图层
          if(this.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer!=null){//REST矢量切片图层
            //移除图层
            this.map.removeLayer(this.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer);
            this.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer = null;
            this.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles = null;
          }
          if(this.allRestVectorLayerArray[iIndex][jIndex].restTileLayer!=null){//REST瓦片图层
            //移除图层
            this.map.removeLayer(this.allRestVectorLayerArray[iIndex][jIndex].restTileLayer);
            this.allRestVectorLayerArray[iIndex][jIndex].restTileLayer = null;
          }
          //图层数组移除图层
          this.allRestVectorLayerArray[iIndex].splice(jIndex,1);
          //判断是否此数据类型的版本号超图图层数组为空
          if(this.allRestVectorLayerArray[iIndex].length==0){
            //清空图例
            this.$emit("getLegendHtml",{name:realName,legendHtml:"",show:false});
          }
          console.log("this.allRestVectorLayerArray--remove");
          console.log(this.allRestVectorLayerArray);
        }
      },
      //重置清空全部超图图层数组
      resetClearAllRestLayerEvent(){
        console.log("重置清空全部超图图层数组");
        let list = this.allRestVectorLayerArray;
        if(list!=null && list.length>0){
          for(let i=0;i<list.length;i++) {
            let selectLayerArray = this.allRestVectorLayerArray[i];
            if(selectLayerArray!=null && selectLayerArray.length>0){
              for(let j=0;j<selectLayerArray.length;j++){
                if(this.allRestVectorLayerArray[i][j]){
                  if (this.allRestVectorLayerArray[i][j].vectorTileLayer != null) {//REST矢量切片图层
                    //移除图层
                    this.map.removeLayer(this.allRestVectorLayerArray[i][j].vectorTileLayer);
                    this.allRestVectorLayerArray[i][j].vectorTileLayer = null;
                    this.allRestVectorLayerArray[i][j].vectorTileStyles = null;
                  }
                  if(this.allRestVectorLayerArray[i][j].restTileLayer!=null){//REST瓦片图层
                    //移除图层
                    this.map.removeLayer(this.allRestVectorLayerArray[i][j].restTileLayer);
                    this.allRestVectorLayerArray[i][j].restTileLayer = null;
                  }
                }
              }
            }
            //清空图层数组
            this.allRestVectorLayerArray[i] = [];
          }
          //清空全部图例
          this.$emit("getLegendHtml",null);
        }
      },
      //根据查询图层信息参数查询并显示图层
      queryLayersByParams(params){
        if(params.radioLabel && params.radioLabel!=="" && params.versionCode && params.versionCode!==""){
          //清空全部选择图层要素
          this.clearAllSelectionLayer();
          for(let i=0;i<this.allRestVectorLayerArray.length;i++){
            for(let j=0;j<this.allRestVectorLayerArray[i].length;j++){
              if(this.allRestVectorLayerArray[i][j].radioLabel===params.radioLabel && this.allRestVectorLayerArray[i][j].versionCode===params.versionCode){
                if(this.allRestVectorLayerArray[i][j].vectorTileLayer!=null){//REST矢量切片图层
                  //移除图层
                  this.map.removeLayer(this.allRestVectorLayerArray[i][j].vectorTileLayer);
                  this.allRestVectorLayerArray[i][j].vectorTileLayer = null;
                  this.allRestVectorLayerArray[i][j].vectorTileStyles = null;
                }
                if(this.allRestVectorLayerArray[i][j].restTileLayer!=null){//REST瓦片图层
                  //移除图层
                  this.map.removeLayer(this.allRestVectorLayerArray[i][j].restTileLayer);
                  this.allRestVectorLayerArray[i][j].restTileLayer = null;
                }
                //地图服务
                //获取数据类型信息
                let dataTypeInfo = this.getDataTypeInfo(params.radioLabel,"radioLabel");
                let url = dataTypeInfo.url;
                console.log(url);
                //test
                //url = "http://10.13.155.192:8090/iserver/services/map-fxfzypg/rest/maps/district_boundary_province@fxfzypg";

                if(params.show) {//显示图层
                  let zIndex = dataTypeInfo.zIndex;
                  let sqlText = params.sqlText;
                  console.log(sqlText);
                  if(sqlText && sqlText!==""){//根据sql条件显示临时图层
                    let layerID = this.allRestVectorLayerArray[i][j].tempLayerId;//临时图层ID
                    if(layerID!=null && layerID!=="") {//指定临时图层ID
                      //更新超图临时图层信息
                      this.getPutTempLayersSet(i,j,url,layerID,zIndex,sqlText);
                    }else{
                      this.createRestMapTempLayersSet(i,j,url,zIndex,sqlText);//查询REST图层信息并创建新的临时图层
                    }
                    //根据url和zIndex、sqlText添加矢量切片图层
                    // this.createVectorTileLayer(i,j,url,zIndex,sqlText);
                  }else{//显示整个图层
                    // this.deleteRestMapTempLayersSet(url,null);//删除超图临时图层
                    // url = "http://10.13.155.192:8090/iserver/services/map-fxfzypg/rest/maps/district_boundary_china@fxfzypg";
                    //根据url、临时图层layerID和zIndex添加瓦片地图图层REST
                    this.createMapRestLayer(i,j,url,'',zIndex);
                    //根据url和zIndex添加矢量切片图层
                    // this.createVectorTileLayer(i,j,url,zIndex,null);
                  }
                }else{//隐藏图层
                  //
                }
                break;
              }
            }
          }
        }
      },
      getLayerLegend(realName,layerUrl,bbox){//根据url获取图层图例信息
        let that = this;
        layerUrl += '/legend.json?bbox='+bbox;
        layerUrl += '&returnVisibleOnly=false';//是否只返回当前地图范围内可见要素的图例。默认为 false
        //图层图例信息查询
        let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        httpRequest.open('GET', layerUrl, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中
        /**
         * 获取数据后的处理程序
         */
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            let layerLegends = obj.layerLegends;
            console.log("layerLegends");
            console.log(layerLegends);
            if(layerLegends!=null && layerLegends.length>0){
              let html = '';
              for(let i=0;i<layerLegends.length;i++){
                let layerLegend = layerLegends[i];
                //获取图层名称
                let layerName = layerLegend.layerName;
                let legends = layerLegend.legends;
                if(legends!=null && legends.length>0){
                  if(layerName.indexOf("#")!=-1 && legends.length==1){
                    let textImgUrl = iServerHttp() + "/iserver/manager/static/Theme/image/LabelUniform.png";
                    //文字图层不显示图例
                    if(legends[0].url==textImgUrl){
                      continue;
                    }
                  }
                  if(legends.length>1){//多图例图层
                    html += '<p style="text-align: center;font-weight: bold;">'+realName+'</p>';
                    for(let j=0;j<legends.length;j++){
                      let legend = legends[j];
                      let values = legend.values;
                      if(values==null){
                        continue;
                      }
                      let imageData = legend.imageData;
                      let contentType = legend.contentType;
                      let url = legend.url;
                      let label = legend.label;
                      let width = legend.width;
                      let height = legend.height;
                      let imgSrc = "data:image/jpeg;base64,"+imageData;
                      html += '<p style="height: '+height+'px;">';
                      html += '<img style="width:'+width+'px;height:'+height+'px" src="'+imgSrc+'" />';
                      html += '<span style="position: relative;top: -2px;left: 10px;height: 16px;font-size: 16px;">'+label+'</span>';
                      html += '</p>';
                    }
                  }else{//单一图例图层
                    layerName = realName;//图层名中文
                    let legend = legends[0];
                    let values = legend.values;
                    let imageData = legend.imageData;
                    let contentType = legend.contentType;
                    let url = legend.url;
                    let label = legend.label;
                    let width = legend.width;
                    let height = legend.height;
                    let imgSrc = "data:image/jpeg;base64,"+imageData;
                    html += '<p style="height: '+height+'px;">';
                    html += '<img style="width:'+width+'px;height:'+height+'px" src="'+imgSrc+'" />';
                    html += '<span style="position: relative;top: -2px;left: 10px;height: 16px;font-size: 16px;">'+layerName+'</span>';
                    html += '</p>';
                  }
                }
              }
              //图例html
              that.$emit("getLegendHtml",{name:realName,legendHtml:html,show:true});
            }
          }
        };
      },
      //根据url和zIndex、sqlText添加矢量切片图层
      createVectorTileLayer(iIndex,jIndex,layerUrl,zIndex,sqlText) {
        let that = this;
        //layerUrl = "http://10.13.155.192:8090/iserver/services/map-fxfzypg/rest/maps/district_boundary_china@fxfzypg";
        //瓦片地图图层
        let mapService = new MapService(layerUrl);//根据超图矢量瓦片图层获取图层信息
        mapService.getMapInfo(function (serviceResult) {
          if(serviceResult.result!=undefined){
            let mapJSONObj = serviceResult.result;
            //获取超图发布的REST图层
            //let options = TileSuperMapRest.optionsFromMapJSON(newUrl, mapJSONObj);
            let layerName = mapJSONObj.name;//图层名称
            //获取图层范围
            let bounds = mapJSONObj.bounds;
            let left = bounds.left;
            let bottom = bounds.bottom;
            let right = bounds.right;
            let top = bounds.top;
            let origin = [left, top];//左上角
            let extent = [left, bottom, right, top];//图层范围
            //获取超图发布的REST矢量切片图层（自定义比例尺）
            let resultArr = getVectorTileLayer(that.map,layerUrl,origin,extent,that.map.getView(),mapJSONObj,sqlText,0);
            let layer = resultArr[0];
            that.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles = resultArr[1];//矢量切片样式
            //自定义样式
            // that.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles.setCustomStyleFuntion(null);
            that.map.addLayer(layer);
            zIndex = zIndex - 1;//test
            //设置图层叠加顺序
            layer.setZIndex(zIndex);
            //添加到REST图层数组
            that.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer = layer;
            // console.log("extent");
            // console.log(extent);
            //缩放到图层范围
            that.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
            //图层范围
            let bbox = extent.join(",");
            //图层显示名称
            let realName = that.allRestVectorLayerArray[iIndex][jIndex].name;
            //获取图例
            that.getLayerLegend(realName,layerUrl,bbox);//根据url获取图层图例信息
          }
        });
      },
      //清空全部选择图层要素
      clearAllSelectionLayer(){
        if(this.selectLayerIndex && this.selectLayerIndex.length==2){
          let iIndex = this.selectLayerIndex[0];
          let jIndex = this.selectLayerIndex[1];
          if(iIndex && jIndex && this.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer){
            //矢量切片样式
            if(this.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles){
              this.allRestVectorLayerArray[iIndex][jIndex].vectorTileStyles.featureSelectedFunction({
                selectedId: null,
                layerName: null,
                fieldId:null
              });
              if(this.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer){
                this.allRestVectorLayerArray[iIndex][jIndex].vectorTileLayer.changed();
              }
            }
          }
        }
      },
      /////////////////////////////////////////////////////////////////////////////////////////超图图层服务end
      //超图数据服务
      //根据经纬度查询当前显示的图层要素数据
      getAllShowLayerFeatureDataByLonLat(lonlat){
        if(this.draw==null && lonlat!=null && lonlat.length==2){//除地图圈选绘制状态
          this.showLayerNum = 0;//当前显示的图层数量
          this.queryLayerNum = 0;//已查询的图层数量
          this.resultDataTypeInfo = null;//已查询到图层要素结果的数据类型信息
          this.resultDataId = null;//已查询到的图层要素主键ID
          this.resultDataFeature = null;//已查询到的图层要素数据
          //清空选中要素高亮显示图层
          this.selectFeatureLayer.getSource().clear();
          //获取当前显示的图层数量
          for(let i=0;i<this.allRestVectorLayerArray.length;i++) {
            if (this.allRestVectorLayerArray[i].length > 0) {
              this.showLayerNum = this.showLayerNum + 1;
            }
          }
          if(this.showLayerNum>0){
            //正在查询
            this.loading = ElLoading.service({
              lock: true,
              text: '正在查询...',
              background: 'rgba(0, 0, 0, 0.7)',
            });
            for(let i=0;i<this.allRestVectorLayerArray.length;i++){
              if(this.allRestVectorLayerArray[i].length>0){
                let code = this.allRestVectorLayerArray[i][0].code;//图层类型code
                //获取数据类型信息
                let dataTypeInfo = this.getDataTypeInfo(code,"code");
                let databaseName = dataTypeInfo.database;
                let tableName = dataTypeInfo.table;
                let sql = dataTypeInfo.sqlFilter;
                sql = "del_flag='0'";
                //经纬度查询图层数据
                this.queryFeatureByLonLat(databaseName,tableName,lonlat,dataTypeInfo,sql);
              }
            }
          }
        }
      },
      queryFeatureByLonLat(databaseName,tableName,lonlat,dataTypeInfo,sql){//经纬度查询图层数据
        if(databaseName && tableName && lonlat!=null && lonlat.length==2 && dataTypeInfo){
          let datasource = databaseName;
          let dataset = tableName;
          // let geomText = "POINT("+lonlat[0]+" "+lonlat[1]+")";
          // //空间数据
          // let feature = new WKT().readFeature(geomText);
          let zoom = this.map.getView().getZoom();
          let temp = Math.pow(2,(18 - zoom));
          //点生成圆多边形
          let meter = 3 * temp;//米
          let degree = meterToDegree(meter);
          let circle = new Circle(lonlat, degree); // 用圆心和半径确定一个圆
          let polygon = new fromCircle(circle) // 得到一个多边形
          let feature = new Feature({
            geometry: polygon
          });
          //添加矢量数据
          // this.selectFeatureLayer.getSource().addFeature(feature);//选中要素高亮显示图层
          this.queryFeatureByGeometry(datasource,dataset,feature,dataTypeInfo,lonlat,sql);//几何查询
        }
      },
      queryFeatureByGeometry(datasource,dataset,feature,dataTypeInfo,lonlat,sql){//根据表名和经纬度几何查询图层要素数据
        let that = this;
        //let url = "http://10.13.155.192:8090/iserver/services/data-fxfzdzzh/rest/data";
        let url = iServerHttp()+"/iserver/services/data-"+datasource+"/rest/data";
        let polygon = feature.getGeometry();
        let geometryParam = new GetFeaturesByGeometryParameters({
          datasetNames: [datasource+":"+dataset],
          geometry: polygon,
          spatialQueryMode: "INTERSECT",
          attributeFilter:sql,//查询过滤条件
        });
        console.log(geometryParam);
        new FeatureService(url).getFeaturesByGeometry(geometryParam, function (serviceResult) {
          console.log("dataset--"+dataset);
          console.log(serviceResult.result);
          if(serviceResult.result){
            let features = serviceResult.result.features.features;
            if(features && features.length>0){
              console.log(features);
              console.log(features[0].properties);
              let fieldId = dataTypeInfo.fieldId.toUpperCase();//主键ID字段名
              //主键ID
              let id = features[0].properties[fieldId];
              if(that.resultDataTypeInfo){//已查询到图层要素结果的数据类型信息
                if(that.resultDataTypeInfo.zIndex < dataTypeInfo.zIndex){//图层顺序大的优先查询
                  that.resultDataTypeInfo = dataTypeInfo;
                  that.resultDataId = id;
                  that.resultDataFeature = features[0];
                }
              }else{
                that.resultDataTypeInfo = dataTypeInfo;
                that.resultDataId = id;
                that.resultDataFeature = features[0];
              }
            }
          }
          that.queryLayerNum = that.queryLayerNum + 1;//已查询的图层数量
          console.log("queryLayerNum:"+that.queryLayerNum+"--"+that.showLayerNum);
          if(that.queryLayerNum==that.showLayerNum){//查询完毕
            if(that.resultDataTypeInfo && that.resultDataId){
              let temp = {
                id:that.resultDataId,
                typeCode:that.resultDataTypeInfo.code
              }
              console.log(temp);
              if(that.resultDataFeature.geometry){
                //空间数据
                let featureTmp = new GeoJSON().readFeature(that.resultDataFeature.geometry);
                let geomType = that.resultDataFeature.geometry.type.toUpperCase();
                if(geomType.indexOf("POINT")!=-1 || geomType.indexOf("MULTIPOINT")!=-1){//点
                  //样式
                  let style = that.getPointStyleByColor("#00ffff");
                  featureTmp.setStyle(style);
                }else if(geomType.indexOf("LINESTRING")!=-1 || geomType.indexOf("MULTILINESTRING")!=-1){//线
                  //样式
                  let style = that.getLineStringStyle("#00ffff");
                  featureTmp.setStyle(style);
                }else if(geomType.indexOf("POLYGON")!=-1 || geomType.indexOf("MULTIPOLYGON")!=-1){//面
                  //样式
                  let style = that.getPolyonStyle("#00ffff");
                  featureTmp.setStyle(style);
                }
                //添加矢量数据
                that.selectFeatureLayer.getSource().addFeature(featureTmp);//选中要素高亮显示图层
                //根据类型显示弹窗
                that.setPopupContentByType(lonlat);
              }
            }
            //查询完毕
            that.loading.close();
          }
        });
      },
      setPopupContentByType(lonlat){//根据类型显示弹窗
        console.log("根据类型显示点击要素属性弹窗");
        let dataTypeInfo = this.resultDataTypeInfo;
        console.log(dataTypeInfo);
        if(dataTypeInfo){//有查询要素数据
          let database = dataTypeInfo.database;
          let type = "矢量数据";
          if(database=="demtif"){
            type = "栅格数据";
          }
          console.log(type);
          if(type=="矢量数据"){
            let typeCode = dataTypeInfo.code;
            let id = this.resultDataId;//主键ID
            let features = this.resultDataFeature;
            let properties = features.properties;
            console.log(dataTypeInfo);
            console.log(id);
            console.log(features);
            console.log(properties);
            let temp = {
              id:id,
              typeCode:dataTypeInfo.code,
              database:dataTypeInfo.database,
              dataTypeInfo:dataTypeInfo,
              smId:properties["SM_ID"]
            }
            //查询数据详情
            this.$emit("getDetailDataById",temp);
            // //获取显示内容
            // let innerHTML = this.getPopupContent(dataTypeInfo,properties);
            // //显示地图弹窗
            // this.setPopupContent(innerHTML);
            // this.popupInfoLayer.setPosition(lonlat);
          }else if(type=="栅格数据"){
            let result = this.resultDataFeature;//栅格信息
            let innerHTML = "行: " + result.row + "<br>";
            innerHTML += "列: " + result.column + "<br>";
            innerHTML += "值: " + result.value + "<br>";
            //显示地图弹窗
            this.setPopupContent(innerHTML);
            this.popupInfoLayer.setPosition(lonlat);
            //清空查询结果表
            let temp = {
              id:null,
              typeCode:null,
              database:null,
              dataTypeInfo:null,
            }
            //查询数据详情
            this.$emit("getDetailDataById",temp);
          }
        }else{//清空查询结果表
          let temp = {
            id:null,
            typeCode:null,
            database:null,
          }
          //查询数据详情
          this.$emit("getDetailDataById",temp);
          this.popupInfoLayer.setPosition(undefined);
        }
      },
      //显示全部超图图层
      showAllLayer(index){
        let that = this;
        setTimeout(function(){
          let dataTypeArray = that.allDataTypeInfoArray;
          if(index<dataTypeArray.length){
            let item = dataTypeArray[index];
            that.allDataList = [item.code,"全部",[],true];//显示超图图层
            //地图显示全部查询结果
            that.showAllListData();
            //显示下一个超图图层
            that.showAllLayer(index+1);
          }
        },1000);
      },
      getAllFeatureCount(){//获取历史设定地震点统计总数
        let datasource = "shpypg";//预评估历史设定地震点数据源
        for(let i=0;i<this.tempDataSetList.length;i++){
          let dataset = this.tempDataSetList[i];
          this.getFeaturesInfo(datasource,dataset);//根据url获取获取要素信息集合
        }
      },
      getFeaturesInfo(datasource,dataset){//根据url获取获取要素信息集合
        let that = this;
        let url = iServerHttp()+"/iserver/services/data-"+datasource+"/rest/data/datasources/name/"+datasource+"/datasets/name/"+dataset+"/features.rjson";//获取要素（feature）信息集合。包括数据集中要素的个数、要素对应的几何对象的类型、各个要素的 URI 等信息。
        //图层图例信息查询
        let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中
        /**
         * 获取数据后的处理程序
         */
        httpRequest.onreadystatechange = function () {
          if (httpRequest.readyState == 4 && httpRequest.status == 200) {
            let json = httpRequest.responseText;//获取到json字符串，还需解析
            let obj = JSON.parse(json);
            let featureCount = obj.featureCount;
            let countObj = {
              dataset:dataset,
              featureCount:featureCount
            }
            that.allFeatureCountArray.push(countObj);//统计个数
            if(that.allFeatureCountArray.length==that.tempDataSetList.length){//历史设定地震点数据个数
              that.allFeatureCount = 0;
              for(let i=0;i<that.allFeatureCountArray.length;i++){
                that.allFeatureCount += that.allFeatureCountArray[i].featureCount;
              }
              that.allFeatureCountBool = true;
            }
          }
        };
      },
      //下载文件
      getDownloadFile() {
        let name = "2020年度晋冀蒙地震危险区地震灾害预评估和应急处置要点报告（简本2）.pdf";
        //清空图例
        this.$emit("getDownloadName",name);
        //隐藏右键菜单窗口
        this.contextmenuLayer.setPosition(undefined);
      },
      //是否开启地图圈选查询
      queryMapEvent(){
        if(this.map!=null){
          if(this.queryMapDrawType=="Polygon"){
            //地图工具箱--开启多边形绘制
            this.setMapToolBox("Polygon");
          }else if(this.queryMapDrawType=="Rectangle"){
            //地图工具箱--开启矩形绘制
            this.setMapToolBox("Rectangle");
          }else if(this.queryMapDrawType=="StopDraw"){
            //地图工具箱--停止绘制
            this.setMapToolBox("StopDraw");
          }else if(this.queryMapDrawType=="Clear"){
            //地图工具箱--清空
            this.setMapToolBox("Clear");
            //清空地图圈选要素高亮显示图层
            this.queryFeatureLayer.getSource().clear();
          }
        }
      },
      //获取绘制数据
      getAllDrawGeomEmit(){
        let list = [];
        //获取全部绘制的空间数据
        let features = this.source.getFeatures();
        if(features!=null && features.length>0) {
          for (let i = 0; i < features.length; i++) {
            let feature = features[i];
            let geom = feature.getGeometry();
            if (geom instanceof Polygon) {//多边形
              let coords = geom.getCoordinates()[0];
              if(coords.length>0){
                let polygonWkt = "POLYGON((";
                for(let i=0;i<coords.length;i++){
                  if(i>0){
                    polygonWkt += ",";
                  }
                  let lonlat = coords[i];
                  polygonWkt += lonlat[0]+" "+lonlat[1];
                }
                polygonWkt += "))";
                list.push(polygonWkt);
              }
            }else if (geom instanceof Point) {
              //点
            }else if (geom instanceof LineString) {
              //线
            }
          }
        }
        // console.log(list);
        //地图圈选查询
        this.$emit("getAllDrawGeom",list);
      },
      //地图圈选查询数据结果高亮显示图层
      showTableDataLayer(){
        let list = this.tableDataList;
        if(this.queryFeatureLayer!=null && this.circleFormObj!=null && list && list.length>0){
          //清空地图圈选要素高亮显示图层
          this.queryFeatureLayer.getSource().clear();
          let tableName = this.circleFormObj.tableName;//表名
          //获取数据类型信息
          let dataTypeInfo = this.getDataTypeInfo(tableName,"table");
          let fieldId = dataTypeInfo.fieldId;
          fieldId = fieldId.replace("_i","I");
          for(let i=0;i<list.length;i++){
            let id = list[i][fieldId];
            let geomText = list[i].geom;
            console.log(geomText);
            let featureTmp = new Feature({
              geometry: (new WKT()).readGeometry(geomText)
            });
            console.log(featureTmp);
            if(geomText.indexOf("POINT")!=-1 || geomText.indexOf("MULTIPOINT")!=-1){//点
              //样式
              let style = this.getPointStyleByColor("#00ffff");
              featureTmp.setStyle(style);
            }else if(geomText.indexOf("LINESTRING")!=-1 || geomText.indexOf("MULTILINESTRING")!=-1){//线
              //样式
              let style = this.getLineStringStyle("#00ffff");
              featureTmp.setStyle(style);
            }else if(geomText.indexOf("POLYGON")!=-1 || geomText.indexOf("MULTIPOLYGON")!=-1){//面
              //样式
              let style = this.getPolyonStyle("#00ffff");
              featureTmp.setStyle(style);
            }
            //设置属性
            featureTmp.setProperties({
              id:id,//主键ID
              tableName:tableName,//表名
            });
            //添加要素
            this.queryFeatureLayer.getSource().addFeature(featureTmp);
          }
        }
      },
    }
  }

</script>

<style scoped>
  /*带三角弹窗*/
  .new-popover {
    position: absolute;
    top:0px;
    left:0px;
    padding:10px;
    background: rgba(0,27,67,0.8);
    color:white;
    z-index:100;
  }
  .new-triangle {
    position: absolute;
    top: 20px;
    left: -19px;
    overflow: hidden;
    width: 0;
    height: 0;
    border-width: 10px;
    border-style: dashed solid dashed dashed;
    border-color:transparent rgba(0,27,67,0.8) transparent transparent;
  }
  .new-contextmenu p {
    width:110px;cursor:pointer;padding:5px;margin-top: 5px;margin-bottom: 5px;
  }
  .new-contextmenu p:hover {
    background: rgba(14, 94, 180, 0.4);border: 1px solid #707070;
  }
  .new-contextmenu div {
    width:100%;
    border-bottom: 1px dashed white;
  }
</style>